package com.klhappy.houyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.klhappy.houyuan.R;
import com.klhappy.houyuan.bean.GoodsNumBean;
import com.klhappy.houyuan.constant.UrlConstant;
import com.klhappy.houyuan.view.ImageManager;

import java.util.List;

/**
 * Created by Administrator on 2015/11/12.
 */
public class FoodsTypeAdapter extends BaseAdapter {

    private Context context;
    private List<GoodsNumBean> list;

    public FoodsTypeAdapter(Context context, List<GoodsNumBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHodler hodler = null;
        if(view == null){
            hodler = new ViewHodler();
            view = LayoutInflater.from(context).inflate(R.layout.item_foods_type ,null);
            hodler.food_img = (ImageView) view.findViewById(R.id.food_img);
            hodler.food_name = (TextView) view.findViewById(R.id.food_name);
            view.setTag(hodler);
        }else{
            hodler = (ViewHodler) view.getTag();
        }

        ImageManager.loadImage(UrlConstant.BASE_URL + list.get(position).getCa_icon(), hodler.food_img);
        hodler.food_name.setText(list.get(position).getCa_name());
        return view;
    }

    class ViewHodler{
        ImageView food_img;
        TextView food_name;
    }
}
